from os import pipe
from typing import MappingView
import xlrd
import pymysql
# 打开数据所在的工作簿，以及选择存有数据的工作表
file_name = r'C:\Users\admin\Desktop\road.xls'
book = xlrd.open_workbook(file_name,formatting_info=True)
sheet = book.sheet_by_name("工作表1")
# 建立一个MySQL连接
conn = pymysql.connect(
        host='localhost', 
        user='root', 
        passwd='root',  
        db='python',  
        port=3306,  
        charset='utf8'
        )
# 获得游标
rowss = 0
# 获取行数
r_num = sheet.nrows
# 获取列数
c_num = sheet.ncols

merge = sheet.merged_cells
read_data = []
for r in range(r_num): # 行
    for c in range(c_num): # 列
        # 读取每个单元格里的数据，合并单元格只有单元格内的第一行第一列有数据，其余空间都为空
        cell_value = sheet.row_values(r)[c]
        # 判断空数据是否在合并单元格的坐标中，如果在就把数据填充进去
        #if cell_value is None or cell_value == '':
        for (rlow, rhigh, clow, chigh) in merge:
            if rlow <= r < rhigh:
                if clow <= c < chigh:
                    cell_value = sheet.cell_value(r, c)
                    print(cell_value)
                    
            
        

"""     read_data.append(nmc)
print(read_data) """